﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AttackExtentItem : Item
{
   /* [Header("两次对同一物体造成伤害的时间间隔")]
    public float DamageGap=0.5f;*/

    public AttackExtentItemField Setting;
    public override ItemField ItemFieldSetting { get => Setting; set => Setting=value as AttackExtentItemField; }

    public override Sprite Sprite =>throw new System.NotImplementedException();

    protected PolygonCollider2D _collider2D;
    public override void DownloadInstanceField(object args)
    {
        base.DownloadInstanceField(args);

        _collider2D.points = (args as AttackExtentItemField).TriggerColliderPoints.ConvertAll<Vector2>(s=>new Vector2(s.x,s.y)).ToArray();
    }

    public override void OnAwake()
    {
        base.OnAwake();
        _collider2D = this.GetComponent<PolygonCollider2D>();
        _collider2D.isTrigger = true;
   //     UploadInstanceField();
     //   (ItemFieldSetting as AttackExtentItemField).TriggerColliderPoints = new List<Vector2>(_collider2D.points);
    }

    public override ItemField UploadInstanceField()
    {
        ItemFieldSetting = base.UploadInstanceField();
        (ItemFieldSetting as AttackExtentItemField).TriggerColliderPoints = new List<Vector2>(_collider2D.points);
        return ItemFieldSetting;
    }
    public override void OnPreferenceDestory()
    {
        base.OnPreferenceDestory();
    }
    public override void OnRealDestory()
    {
  //      base.OnRealDestory();
    }

    public override void OnStart()
    {
    //    throw new System.NotImplementedException();
    }
    /*public Dictionary<string, float> lastDamageTime;
public void OnCollisionStay2D(Collision2D collision)
{
   if (collision.collider.GetItemName() != default)
   {
       string name = collision.collider.GetItemName();
       if (lastDamageTime.ContainsKey(name) == false || Time.time - lastDamageTime[name] > DamageGap)
       {
           lastDamageTime[name] = Time.time;
       }
   }
}*/
}
[System.Serializable]
public class AttackExtentItemField:ItemField
{
    //local position
    public List<Vector2> TriggerColliderPoints;
    public float Power;
    [HideInInspector]
    public bool DeadWhenCollide = false;
}
